package com.testdemo.web.shapecalc.impl;

import com.testdemo.web.question.IShapeCalcQusition;

public abstract class ShapeQuestionImpl implements IShapeCalcQusition {
	/*
	  * 正确面积
	  */
	 double Area;
	 /*
	  * 正确周长
	  */
	 double Perimeter;
	 /*
	  * 回答的周长
	  */
	 double PerimeterAnswer;
	 /*
	  * 回答的面积
	  */
	 double AreaAnswer;
	 /*
	  * 题目名称
	  */
	 String Name;	 
	 
	 boolean isRightArea;
	 boolean isRightPerimeter;
	 
	 /*
	  * 回答正确情况.
	  */
	 String AnswerInfo;
	 
	 
	 public ShapeQuestionImpl(){
		 Area = -1;
		 Perimeter = -1;
		 AreaAnswer = -1;
		 PerimeterAnswer = -1;
		 
		 Name = "未知图形";
		 AnswerInfo = "未答题";
	 }
	 @Override
	 public String getShapeName()
	 {
		 return Name;
	 }
	 
	 protected void CalcArea()
	 {
		 Area = 0;
	 }
	 protected void CalcPerimeter()
	 {
		 Perimeter = 0;
	 }
	@Override
	public double getRightArea() {
		return Area;
	}
	@Override
	public double getRightPerimeter() {
		return Perimeter;
	}
	@Override
	public boolean setAreaAnswer(double area) {
		this.AreaAnswer = area;
		if (Area == area)
			isRightArea = true;
		else
			isRightArea = false;
		
		return isRightArea;
	}
	@Override
	public boolean setPerimeterAnswer(double perimeter) {
		this.PerimeterAnswer = perimeter;
		if (Perimeter == perimeter)
			isRightPerimeter = true;
		else
			isRightPerimeter = false;
		
		return isRightPerimeter;
	}

	@Override
	public boolean AnseweredArea() {
		if (this.AreaAnswer == -1)
		return false;
		else
			return true;
	}
	@Override
	public boolean AnseweredPerimeter() {
		if (this.PerimeterAnswer == -1)
			return false;
		else
			return true;
	}
	@Override
	public String getRightAnswerString() {
		String temp;
		temp = "答案：" + Name + "的面积正确答案是： " + Double.toString(Area) + "。\r\n";
		temp +="     " + Name + "的周长正确答案是： " + Double.toString(Perimeter) + "。";
		
		return temp;
	}

	@Override
	public String getAnsewerString() {
		String temp;
		temp = "答案：" + Name + "的面积正确答案是： " + Double.toString(AreaAnswer) + "。\r\n";
		temp +="     " + Name + "的周长正确答案是： " + Double.toString(PerimeterAnswer) + "。";
		
		return temp;
	}

	@Override 
	public String getAnswerInfo() {
		AnswerInfo = "";
	    if (this.AnseweredArea())
	    {
	    	if (this.isRightArea)
	    	{
	    		AnswerInfo += "本题面积答案正确";
	    		
	    	}else
	    	{
	    		AnswerInfo += "本题面积答案错";
	    	}
	    	
	    }
	    else
	    {
	    	AnswerInfo += "本题未回答面积答案";
	    
	    }
	    
	    if (this.AnseweredPerimeter())
	    {
	    	if (this.isRightPerimeter)
	    	{
	    		AnswerInfo += "本题面积答案正确";
	    		
	    	}else
	    	{
	    		AnswerInfo += "本题面积答案错";
	    	}
	    	
	    }
	    else
	    {
	    	AnswerInfo += "，本题未回答周长答案。";
	    
	    }
		 
		return AnswerInfo;
	}
	@Override 
	public String getPageType()
	{
		return "calc";
	}

}
